
<style lang="less" scoped>
  .page__wrapper {
    width: 100%;
    height: 100%;
  }
</style>

<template>
  <div class="page__wrapper" @keydown.enter="handleDataSearch">
    <simple-table :table-column="tableColumn" :table-data="tableData" :table-page-info="tablePageInfo" :table-data-count="tableDataTotalCount" @page-info-change="handlePageInfoChange" show-summary :summary-method="handleSummaryMethod">
      <template slot="searchSection">
        <simple-form v-model="searchModel" :form-field="searchFormField">
          <template slot="tableOperation">
            <el-button @click="handleDataSearch">{{$t('operation.search')}}</el-button>
            <el-button v-if="searchModel.companyid" @click="handleBack" type="primary">返回</el-button>
          </template>
        </simple-form>
      </template>
      <template slot-scope="scope" slot="uploadquarter">
        {{ $getDictLabel({type: '季度', value: scope.row.uploadquarter}) }}
      </template>
      <template slot-scope="scope" slot="orgname">
        <el-tag v-if="scope.row.companytype !== 'org_type_3'" style="cursor:pointer" @click="handleOrgnameClick(scope.row)">{{scope.row.orgname}}</el-tag>
        <template v-else>{{scope.row.orgname}}</template>
      </template>
      <template slot-scope="scope" slot="companytype1">
        {{ $getDictLabel({type: '公司性质', value: scope.row.companytype1}) }}
      </template>
      <template slot-scope="scope" slot="propertytype">
        {{ $getDictLabel({type: '产权性质_厂办', value: scope.row.propertytype}) }}
      </template>
      <template slot-scope="scope" slot="isconfirmation">
        {{ $getDictLabel({type: '是否', value: scope.row.isconfirmation}) }}
      </template>
      <template slot-scope="scope" slot="businessstatus">
        {{ $getDictLabel({type: '经营状态_厂办', value: scope.row.businessstatus}) }}
      </template>
      <template slot-scope="scope" slot="reformmethod">
        {{ $getDictLabel({type: '改革方式_厂办', value: scope.row.reformmethod}) }}
      </template>
      <template slot-scope="scope" slot="isrestructuring">
        {{ $getDictLabel({type: '是否', value: scope.row.isrestructuring}) }}
      </template>
      <template slot-scope="scope" slot="iscompletereform">
        {{ $getDictLabel({type: '是否', value: scope.row.iscompletereform}) }}
      </template>
      <template slot-scope="scope" slot="isinsolvent">
        {{ $getDictLabel({type: '是否', value: scope.row.isinsolvent}) }}
      </template>
      <template slot-scope="scope" slot="profitloss">
        {{ $getDictLabel({type: '盈亏情况', value: scope.row.profitloss}) }}
      </template>
    </simple-table>
  </div>
</template>
<script>
import Axios from 'axios'
/** 混入分页信息及数据总数信息 */
import pageMixins from '@/components/base/simple-table/page-mixins'
const BASEURL = {
  list: `/web/statistic/ajax.html?sys_method=GetList&sys_objName=V_Statistic_Unlisted_Custody_Business&sys_tableName=V_Statistic_Unlisted_Custody_Business`,
  summary: `/web/statistic/ajax.html?sys_method=GetList&sys_objName=V_Statistic_Unlisted_Custody_Business_Count&sys_tableName=V_Statistic_Unlisted_Custody_Business_Count`,
  getInitConfig: '/Web/SysAdmin/ajax.html?sys_method=GetInitConfig',
  getCombobox: '/Web/SysAdmin/ajax.html?sys_method=GetCombobox'
}
export default {
  name: 'statistic_unlisted',
  mixins: [pageMixins],
  data () {
    return {
      searchModel: {
        uploadyear: this.$moment().format('YYYY'),
        uploadquarter: String(this.$moment().quarter())
      },
      /** 表格数据 */
      tableData: [],
      summaryData: {},
      actionList: [],
      sys_mid: '',
      orgList: []
    }
  },
  computed: {
    searchFormField () {
      return [
        // Todo: 高级查询暂时未加企业名称 需要与后台去人谁去做数据过滤
        { prop: 'uploadyear', label: this.$t('balance_unlisted.uploadyear'), type: 'Datepicker', component: { clearable: true, type: 'year', valueFormat: 'yyyy' } },
        { prop: 'uploadquarter', label: this.$t('balance_unlisted.uploadquarter'), type: 'Select', component: { clearable: true, optionList: this.$getDictList('季度') } },
        { slotName: 'tableOperation', col: { span: 12, style: { textAlign: 'right' } }, labelWidth: '0' }
      ]
    },
    tableColumn () {
      return [
        { prop: 'orgname', label: '公司名称', slotName: 'orgname', width: 200, fixed: 'left' },
        { prop: 'uploadyear', label: this.$t('balance_unlisted.uploadyear'), width: 50, fixed: 'left' },
        { prop: 'uploadquarter', label: this.$t('balance_unlisted.uploadquarter'), slotName: 'uploadquarter', width: 70, fixed: 'left' },

        // 改革推进情况
        { label: this.$t('balance_unlisted.reform'),
          children: [
            { label: this.$t('balance_unlisted.busiandlevethree'),
              children: [
                { prop: 'bizcategory1', label: this.$t('balance_unlisted.bizcategory1'), width: 80 },
                { prop: 'bizcategory2', label: this.$t('balance_unlisted.bizcategory2'), width: 80 }
              ]
            },
            { prop: 'reformmethod', label: this.$t('balance_unlisted.reformmethod'), slotName: 'reformmethod', width: 70 },
            { prop: 'totalprofit2015', label: this.$t('balance_unlisted.totalprofit2015'), width: 70 },
            { label: this.$t('balance_unlisted.unbusicharge'),
              children: [
                { prop: 'subtotalnonoperatingcost', label: this.$t('balance_unlisted.subtotalnonoperatingcost'), width: 70 },
                { prop: 'repairreconstructioncost', label: this.$t('balance_unlisted.repairreconstructioncost'), width: 95 },
                { prop: 'assetimpairmentloss', label: this.$t('balance_unlisted.assetimpairmentloss'), width: 85 },
                { prop: 'resettlementcost', label: this.$t('balance_unlisted.resettlementcost'), width: 70 }
              ]
            },
            { prop: 'reformmeasuresprogress', label: this.$t('balance_unlisted.reformmeasuresprogress'), width: 70 },
            { prop: 'existingproblem', label: this.$t('balance_unlisted.existingproblem'), width: 70 }
          ]
        },

        // 资产负债情况
        { label: this.$t('balance_unlisted.assetliabilitie'),
          children: [
            { label: this.$t('balance_unlisted.endTerm'),
              children: [
                { label: this.$t('balance_unlisted.asset'),
                  children: [
                    { prop: 'totalassets', label: this.$t('balance_unlisted.totalassets'), width: 70 },
                    { prop: 'currencyfund', label: this.$t('balance_unlisted.currencyfund'), width: 70 },
                    { prop: 'stocknetreceivables', label: this.$t('balance_unlisted.stocknetreceivables'), width: 90 },
                    { prop: 'netvalueoffixedassets', label: this.$t('balance_unlisted.netvalueoffixedassets'), width: 60 },
                    { prop: 'buildingassets', label: this.$t('balance_unlisted.buildingassets'), width: 90 },
                    { prop: 'miningassets', label: this.$t('balance_unlisted.miningassets'), width: 70 }
                  ]
                },
                { label: this.$t('balance_unlisted.liability'),
                  children: [
                    { prop: 'totalliabilities', label: this.$t('balance_unlisted.totalliabilities'), width: 70 },
                    { prop: 'shorttermnegativeinterest', label: this.$t('balance_unlisted.shorttermnegativeinterest'), width: 60 },
                    { prop: 'assetsliabilities', label: this.$t('balance_unlisted.assetsliabilities'), width: 60 }
                  ]
                }
              ]
            }]
        },

        // 非矿区业务经营情况
        { label: this.$t('balance_unlisted.unminingareab'),
          children: [
            { label: this.$t('balance_unlisted.currentmonth'),
              children: [
                { label: this.$t('balance_unlisted.businessincome'),
                  children: [
                    { prop: 'totalincomequarter', label: this.$t('balance_unlisted.totalincomequarter'), width: 60 },
                    { prop: 'internalcompanyincomequarter', label: this.$t('balance_unlisted.internalcompanyincomequarter'), width: 70 },
                    { prop: 'externalcompanyincomequarter', label: this.$t('balance_unlisted.externalcompanyincomequarter'), width: 70 }
                  ]
                },
                { label: this.$t('balance_unlisted.cost'),
                  children: [
                    { prop: 'totalcostquarter', label: this.$t('balance_unlisted.totalcostquarter'), width: 60 },
                    { prop: 'laborcostquarter', label: this.$t('balance_unlisted.laborcostquarter'), width: 70 },
                    { prop: 'interestexpensequarter', label: this.$t('balance_unlisted.interestexpensequarter'), width: 70 },
                    { prop: 'depreciationdepletionquarter', label: this.$t('balance_unlisted.depreciationdepletionquarter'), width: 70 }
                  ]
                },
                { prop: 'totalprofitquarter', label: this.$t('balance_unlisted.totalprofitquarter'), width: 70 }
              ]
            },
            { label: this.$t('balance_unlisted.currentyear'),
              children: [
                { label: this.$t('balance_unlisted.businessincome'),
                  children: [
                    { prop: 'totalincomeyear', label: this.$t('balance_unlisted.totalincomeyear'), width: 60 },
                    { prop: 'internalcompanyincomeyear', label: this.$t('balance_unlisted.internalcompanyincomeyear'), width: 70 },
                    { prop: 'externalcompanyincomeyear', label: this.$t('balance_unlisted.externalcompanyincomeyear'), width: 70 }
                  ]
                },
                { label: this.$t('balance_unlisted.cost'),
                  children: [
                    { prop: 'totalcostyear', label: this.$t('balance_unlisted.totalcostyear'), width: 60 },
                    { prop: 'laborcostyear', label: this.$t('balance_unlisted.laborcostyear'), width: 70 },
                    { prop: 'interestexpenseyear', label: this.$t('balance_unlisted.interestexpenseyear'), width: 70 },
                    { prop: 'depreciationdepletionyear', label: this.$t('balance_unlisted.depreciationdepletionyear'), width: 70 }
                  ]
                },
                { prop: 'totalprofityear', label: this.$t('balance_unlisted.totalprofityear'), width: 70 }
              ]
            }
          ]
        },

        // 矿区业务经营情况
        { label: this.$t('balance_unlisted.miningareab'),
          children: [
            { label: this.$t('balance_unlisted.currentyear'),
              children: [
                { label: this.$t('balance_unlisted.businessincome'),
                  children: [
                    { prop: 'totalincome', label: this.$t('balance_unlisted.totalincome'), width: 50 },
                    { label: this.$t('balance_unlisted.extrevenue'),
                      children: [
                        { prop: 'totalexternalincome', label: this.$t('balance_unlisted.totalexternalincome'), width: 60 },
                        { prop: 'socialincome', label: this.$t('balance_unlisted.socialincome'), width: 60 },
                        { prop: 'industrialserviceincome', label: this.$t('balance_unlisted.industrialserviceincome'), width: 60 },
                        { prop: 'landleaseandotherincome', label: this.$t('balance_unlisted.landleaseandotherincome'), width: 85 },
                        { prop: 'incomingandoutgoing', label: this.$t('balance_unlisted.incomingandoutgoing'), width: 70 }
                      ]
                    },
                    { prop: 'listedcompany', label: this.$t('balance_unlisted.listedcompany'), width: 80 },
                    { prop: 'unlistedcompany', label: this.$t('balance_unlisted.unlistedcompany'), width: 90 }
                  ]
                },
                { label: this.$t('balance_unlisted.nonoperatingincome'),
                  children: [
                    { prop: 'totalnonoperatingincome', label: this.$t('balance_unlisted.totalnonoperatingincome'), width: 85 },
                    { prop: 'groupsubsidy', label: this.$t('balance_unlisted.groupsubsidy'), width: 70 }
                  ]
                },
                { label: this.$t('balance_unlisted.cost'),
                  children: [
                    { prop: 'totalcostmining', label: this.$t('balance_unlisted.totalcostmining'), width: 60 },
                    { prop: 'laborcostmining', label: this.$t('balance_unlisted.laborcostmining'), width: 70 },
                    { prop: 'depreciationdepletionmining', label: this.$t('balance_unlisted.depreciationdepletionmining'), width: 70 },
                    { prop: 'othermining', label: this.$t('balance_unlisted.othermining'), width: 50 }
                  ]
                },
                { prop: 'totalprofitmining', label: this.$t('balance_unlisted.totalprofitmining'), width: 70 }
              ]
            }
          ]
        },

        // 人员情况
        { label: this.$t('balance_unlisted.thestaff'),
          children: [
            { label: this.$t('balance_unlisted.currentyearchange'),
              children: [
                {
                  label: this.$t('balance_unlisted.reduce'), // 减员
                  children: [
                    { prop: 'subtotalreduction', label: this.$t('balance_unlisted.subtotalreduction'), width: 70 },
                    { prop: 'naturalreduction', label: this.$t('balance_unlisted.naturalreduction'), width: 70 },
                    { prop: 'agreementcancellation', label: this.$t('balance_unlisted.agreementcancellation'), width: 70 },
                    { prop: 'specialtypeearlyretirement', label: this.$t('balance_unlisted.specialtypeearlyretirement'), width: 70 },
                    { prop: 'transferlisted', label: this.$t('balance_unlisted.transferlisted'), width: 70 },
                    { prop: 'otherreduction', label: this.$t('balance_unlisted.otherreduction'), width: 50 }]
                },
                { label: this.$t('balance_unlisted.increase'), // 增员
                  children: [
                    { prop: 'subtotalincrease', label: this.$t('balance_unlisted.subtotalincrease'), width: 70 },
                    { prop: 'undergraduate', label: this.$t('balance_unlisted.undergraduate'), width: 60 },
                    { prop: 'demobilizedserviceman', label: this.$t('balance_unlisted.demobilizedserviceman'), width: 70 },
                    { prop: 'otherincrease', label: this.$t('balance_unlisted.otherincrease'), width: 50 }
                  ]
                }
              ]
            },
            { label: this.$t('balance_unlisted.currentyear'), // 本年累计
              children: [
                { label: this.$t('balance_unlisted.currentemployeenum'), // 期末在职人数
                  children: [
                    { prop: 'totalcurrentemployee', label: this.$t('balance_unlisted.totalcurrentemployee'), width: 60 },
                    { prop: 'contractemployeecurrent', label: this.$t('balance_unlisted.contractemployeecurrent'), width: 60 },
                    { prop: 'marketemployeecurrent', label: this.$t('balance_unlisted.marketemployeecurrent'), width: 60 },
                    { prop: 'laboremployeecurrent', label: this.$t('balance_unlisted.laboremployeecurrent'), width: 70 }
                  ]
                },
                { prop: 'perlaborcost', label: this.$t('balance_unlisted.perlaborcost'), width: 60 }
              ]
            }
          ]
        }
      ]
    }
  },
  methods: {
    handleDataSearch () {
      let params = Object.assign({}, this.tablePageInfo, { sys_mid: this.sys_mid }, { sys_search: this.searchModel })

      let loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      Axios.all([
        this.$axios.post(BASEURL.list, this.$_.cloneDeep(params)),
        this.$axios.post(BASEURL.summary, this.$_.cloneDeep(params))
      ])
        .then(Axios.spread((listResp, countResp) => {
          this.tableData = listResp.rows
          this.tableDataTotalCount = listResp.total

          this.summaryData = countResp.rows[0] || {}
        }))
        .finally(() => {
          loadingFlag.close()
        })
    },
    handleInitData () {
      let configLoadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      this.$axios.post(BASEURL.getInitConfig)
        .then(resp => {
          this.actionList = resp.actionKeys.split(',')
          this.sys_mid = resp.mid

          /** 设置列表及涉及主数据请求参数 */
          let params = Object.assign({}, this.tablePageInfo, { sys_mid: resp.mid }, { sys_search: this.searchModel })
          let comboParams = { sys_json: JSON.stringify([{ ObjName: 'C_SYS_Role' }, { ObjName: 'C_SYS_Org' }]) }
          let loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })

          Axios.all([
            this.$axios.post(BASEURL.getCombobox, comboParams),
            this.$axios.post(BASEURL.list, this.$_.cloneDeep(params)),
            this.$axios.post(BASEURL.summary, this.$_.cloneDeep(params))
          ])
            .then(Axios.spread((comboData, listResp, countResp) => {
              this.orgList = comboData.C_SYS_Org

              this.tableData = listResp.rows
              this.tableDataTotalCount = listResp.total

              this.summaryData = countResp.rows[0] || {}
            }))
            .finally(() => {
              loadingFlag.close()
            })
        })
        .finally(() => {
          configLoadingFlag.close()
        })
    },
    handleOrgnameClick (row) {
      this.searchModel.companyid = row.orgid
      this.handleDataSearch()
    },
    handleBack () {
      delete this.searchModel.companyid
      this.handleDataSearch()
    },
    handleSummaryMethod (param) {
      let { columns } = param
      let sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
        } else if (index < 3) {
          // 年份、季度显示 -
          sums[index] = '-'
        } else {
          sums[index] = this.summaryData[column.property]
        }
      })
      return sums
    }
  },
  mounted () {
    this.handleInitData()
  }
}
</script>
